package com.gr3g.dev.learndraw.model.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;

/** @author Gregory Tardivel */
public final class FreeDrawView extends AbstractDrawView {

	/**
	 * Constructeur.
	 * 
	 * @param pContext
	 */
	public FreeDrawView(final Context pContext) {
		super(pContext);
	}

	/**
	 * Constructeur.
	 * 
	 * @param pContext
	 * @param pAttrs
	 * @param pDefStyleAttr
	 */
	public FreeDrawView(final Context pContext, final AttributeSet pAttrs,
			final int pDefStyleAttr) {
		super(pContext, pAttrs, pDefStyleAttr);
	}

	/**
	 * Constructeur.
	 * 
	 * @param pContext
	 * @param pAttrs
	 */
	public FreeDrawView(final Context pContext, final AttributeSet pAttrs) {
		super(pContext, pAttrs);
	}

	public void changeColor(final int color) {
		this.paint.setColor(color);
	}

	@Override
	protected void initBitmap(final float pWidth, final float pHeight) {
		// Bitmap fond blanc
		this.bitmap = Bitmap.createBitmap((int) pWidth, (int) pHeight,
				Bitmap.Config.ARGB_8888);
		this.canvasBitmap = new Canvas(this.bitmap);
		this.canvasBitmap.drawColor(Color.WHITE);
	}

	public void setBitmap(final Bitmap pBitmap) {
		this.bitmap = Bitmap.createBitmap(pBitmap.getWidth(),
				pBitmap.getHeight(), Bitmap.Config.ARGB_8888);
		this.canvasBitmap = new Canvas(this.bitmap);
		this.canvasBitmap.drawBitmap(pBitmap, 0, 0, this.paint);
	}

	public Bitmap getBitmap() {
		return this.bitmap;
	}
}
